<?php
/*
    Copyright (C) 2008 - 2010 Inanta Martsanto
    
    This file is part of Koma.

    Koma is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Koma is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Koma.  If not, see <http://www.gnu.org/licenses/>.
    
    Inanta Martsanto (inanta@inationsoft.com)
*/

final class KomaRoutines extends KomaSingletonObject
{	
	public function __construct()
	{
		$this->includeOnce(array(
				KOMA_INCLUDE_PATH.'/version.inc.php', KOMA_INCLUDE_PATH.'/config.inc.php',
				KOMA_INCLUDE_PATH.'/show_message.inc.php', KOMA_INCLUDE_PATH.'/redirect.inc.php',
                                KOMA_INCLUDE_PATH.'/shutdown.inc.php',
				KOMA_INCLUDE_PATH.'/php-gettext-1.0.7/gettext.inc', KOMA_INCLUDE_PATH.'/gettext_init.inc.php',
				));
	}
	
	public function includeOnce($files)
	{
		if(is_array($files))
		{
			foreach($files as $file)
			{
				if(!file_exists($file))
				{
					throw new KomaIOException(array('code' => FILE_NOT_FOUND,
                                                                        'filename' => $file));
				}
				
				@include_once($file);
			}
		}
		else
		{
			if(!file_exists($files))
			{
				throw new KomaIOException(array('code' => FILE_NOT_FOUND,
                                                                'filename' => $files));
			}
			
			@include_once($files);
		}
	}
	
	public function loadLanguage($locale = 'en_US', $charset = 'UTF-8')
	{
		gettext_init($locale, 'main', KOMA_LOCALE_PATH, $charset);
	}
	
	public function isDebugMode()
	{
		return true;
	}
	
	static function getInstance()
	{
                return self::createInstance(__CLASS__);
	}
}
?>